package pjkanri.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pjkanri.dao.DAOException;
import pjkanri.entity.Project;
import pjkanri.service.ProjectService;

/**
 * Servlet implementation class CreateProjectServlet
 */
@WebServlet("/createproject")
public class CreateProjectServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
				// リクエスト・パラメーターの取得
				String name = request.getParameter("name");
				String desc = request.getParameter("description");
//				System.out.println(name +" ------------ "+ desc);

				try {
						ProjectService.insert(new Project(null, name, desc));

				} catch (DAOException e) {
					e.printStackTrace();
				}

//				// リクエスト・パラメーターの取得
//
//				String forwardPath = "projectList.jsp";
//
//				// 転送処理
//				request.getRequestDispatcher(forwardPath).forward(request, response);
				
				ServletContext sc = getServletContext();  
				RequestDispatcher rd = sc.getRequestDispatcher("/projectlist");  
				rd.forward(request, response);
	}

}
